package com.sky.exceptor;

import com.sky.exception.BusinessException;
import com.sky.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {
    //处理自定义异常处理
    @ExceptionHandler(BusinessException.class)
    public Result handlerBusinessException(BusinessException e) {
        log.error("出现业务异常:{}", e);
        return Result.error(e.getCode(), e.getMessage());
    }

    //兜底异常 所有异常都能处理
    @ExceptionHandler(Exception.class)
    public Result handlerException(Exception e) {
        log.error("出现未知错异常:{}", e);
        return Result.error(500, "系统异常，请稍后重试");
    }
}
